package com.example.weddingapp.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;

import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;


import com.example.weddingapp.R;

import cn.leancloud.AVUser;


/**
 * @Date 2020/5/6 10:06
 * @Desc 闪屏页
 */

public class SplashActivity extends AppCompatActivity {
    private Animation animation;
    private ConstraintLayout parent_layout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        initView();
    }

    private void initView() {
        parent_layout = (ConstraintLayout) findViewById(R.id.parent_layout);
        //动画结束后跳转到主页
        animation = new AlphaAnimation(0.0f, 1.0f);
        animation.setDuration(1000);

        parent_layout.startAnimation(animation);
        animation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                if (AVUser.getCurrentUser() != null) {
                    startActivity(new Intent(SplashActivity.this, MainActivity.class));
                    finish();
                    return;
                }
                startActivity(new Intent(SplashActivity.this, LoginActivity.class));
                finish();
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
    }
}
